<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
	<% include ../head.html %>
</head>
<body>
	<div id="head">
		<% include ../top_bar.html %>
		<script type="text/javascript">$('#index').addClass('active');</script>
	</div>
	<div id="wrap">
		<div id="main">
			<div id="content">
				<div class="panel">
				    <div id="innner">
						<div>
							<ul class="breadcrumb">
							    <li><a href="#">首页</a> <span class="divider">/</span></li>
							    <li class="active">吐槽内容</li>
						    </ul>
						</div>
						<div class="topic-main">
						<% if(topic){ %>
							<div style="padding: 10px 0;">
								<div style=""><h2><%=topic.title%></h2></div>
								<hr>
								<div><%-mdConverter.makeHtml(topic.content) %></div>
								<hr>
								<div>
									<div>
										标签: <span class="label label-important"><%=topic.tag%></span>
									</div>
									<div>
										<%=topic.loginname%> 在 <%=dateformat(topic.create_time, 'mm-dd HH:MM')%> 吐槽  <%=topic.loginname%> 在 <%=dateformat(topic.update_time, 'mm-dd HH:MM')%> 编辑
									</div>
									<div>
										<button type="button" class="btn btn-success">收藏一下</button>
									</div>
								</div>
							</div>
						<% }else{ %>
							<div>当前吐槽已经不纯在了!</div>
						<% } %>
						</div>
				    </div>
				</div>
				<div class="panel">
					<div class="header"><%=topic.reply_count%> 吐槽</div>
					<% var f=1;for(var r in reply){ %>
					<div class="inner" style="border-bottom: 1px solid #E5E5E5;">
						<div class="inner">
							<div>
								<a href="../user/<%=reply[r].user.name%>"><img src="<%=site_host%>/saonian.jpg" class="img-rounded" /></a>
								<span class="username"><%=reply[r].user.name%></span>
								<a><%=dateformat(reply[r].reply_time, 'mm-dd HH:MM')%></a>
								<span class="username" style="float:right">
									<%=f%>楼
									<a href="#">回复</a>
								</span>
							</div>
							<div style="margin-left: 70px;">
								<%-mdConverter.makeHtml(reply[r].content)%>
							</div>
						</div>
						<% if(reply[r].child.length > 0){ 
							for(var i=0; i < reply[r].child.length; i++){
						%>
						<div class="inner" style="margin-left: 50px;border-top: 1px solid #EEEEEE;">
							<div>
								<a href="../user/<%=reply[r].user.name%>"><img src="<%=site_host%>/saonian.jpg" class="img-rounded" /></a>
								<span class="username"><%=reply[r].user.name%></span>
								<a><%=dateformat(reply[r].reply_time, 'mm-dd HH:MM')%></a>
							</div>
							<div style="margin-left: 70px;">
								<%-mdConverter.makeHtml(reply[r].child[i].content) %>
							</div>
						</div>
						<% } } %>
					</div>
					<% f++;} %>
				</div>
				<div class="panel">
					<div class="header">吐槽几句</div>
					<% if(user){ %>
					<div class="inner">
						<form action="/topic/reply" method="post" id="form1" class="form-horizontal">
							<input type="hidden" name="topic_id" value="<%=topic.id%>"/>
							<input type="hidden" name="topic_uuid" value="<%=topic.uuid%>"/>
							<div class="inner">
								<ul class="nav nav-pills">
									<li class="active"><a data-toggle="pill" href="#markdown">markdown</a></li>
									<li><a class="preview-btn" data-toggle="pill"
										href="#preview">预览</a></li>
									<!-- <li><a data-toggle="pill" href="#tags">标签</a></li> -->
								</ul>
								<div class="tab-content">
									<div id="markdown" class="active tab-pane">
										<div id="wmd-button-bar"></div>
										<div class="input">
											<textarea rows="20" name="content" id="wmd-input" class="content-txtarea" placeholder="卧槽。。。"></textarea>
										</div>
									</div>
									<div class="tab-pane" id="preview">
										<div class="wmd-preview topic-wmd-preview" id="wmd-preview"></div>
									</div>
									<div class="tab-pane" id="tags">
										<div class="tags_select">
										</div>
									</div>
								</div>
							</div>
							<div class="inner">
								<button type="button" id="save_btn" class="btn btn-success">发布</button>
							</div>
						</form>
					</div>
					<% }else{ %>
					<div class="inner">
						先<a href="/login">登录</a>再留下节操吧~
					</div>
					<% } %>
				</div>
			</div>
			<div id="sidebar">
				<% include ../user/user_info.html %>
				<div class="panel">
					<div class="header">热门吐槽</div>
					<div class="inner">
						ddd
					</div>
				</div>
			</div>
		</div>
	</div>
	<div id="foot">
	
	</div>
	<script type="text/javascript" src="<%=site_host%>/markdown/Markdown.Converter.js"></script>
	<script type="text/javascript" src="<%=site_host%>/markdown/Markdown.Editor.js"></script>
	<script type="text/javascript" src="<%=site_host%>/markdown/showdown.js"></script>
	<script type="text/javascript" src="<%=site_host%>/commen.js"></script>
	<script type="text/javascript">
		$('#save_btn').click( function(){
			$('#form1').submit();
		});
		$(document).ready(function () {
            var editor;
            function run_md_editor() {
                var converter = new Showdown.converter();
                editor = new Markdown.Editor(converter);
                editor.run();
            }
            run_md_editor();
            
            $('#wmd-input').mouseover(function(){
                $('#wmd-input').focus()
            });
            $('.preview-btn').click(function() {
                editor.makePreviewHtml();
            });
            document.onkeyup=function(event) {
                if(window.ActiveXObject) {
                    var keydown = window.event.keyCode;
                    event=window.event;
                }else{
                    var keydown = event.keyCode;
                    if(event.ctrlKey == true && keydown == 13){
                        if(submit_btn){
                            submit_btn.click();
                        }
                    }
                }
            };
        });
		
	</script>
</body>
	
</html>